<?php

function playerCompletionsSort($a, $b) {
  return $a->completions == $b->completions ? playerSPPsSort($a, $b) : $b->completions - $a->completions;
}

function playerTDsSort($a, $b) {
  return $a->tds == $b->tds ? playerSPPsSort($a, $b) : $b->tds - $a->tds;
}

function playerInterceptionsSort($a, $b) {
  return $a->interceptions == $b->interceptions ? playerSPPsSort($a, $b) : $b->interceptions - $a->interceptions;
}

function playerCasualtiesSort($a, $b) {
  return $a->casualties == $b->casualties ? playerSPPsSort($a, $b) : $b->casualties - $a->casualties;
}

function playerMVPsSort($a, $b) {
  return $a->mvps == $b->mvps ? playerSPPsSort($a, $b) : $b->mvps - $a->mvps;
}

function playerExpsSort($a, $b) {
  return $a->exps == $b->exps ? playerSPPsSort($a, $b) : $b->exps - $a->exps;
}

function playerSPPsSort($a, $b) {
  return $b->getSPPs() - $a->getSPPs();
}

function playerMaSort($a, $b) {
  return $a->ma == $b->ma ? playerSPPsSort($a, $b) : $b->ma - $a->ma;
}

function playerStSort($a, $b) {
  return $a->st == $b->st ? playerSPPsSort($a, $b) : $b->st - $a->st;
}

function playerAgSort($a, $b) {
  return $a->ag == $b->ag ? playerSPPsSort($a, $b) : $b->ag - $a->ag;
}

function playerAvSort($a, $b) {
  return $a->av == $b->av ? playerSPPsSort($a, $b) : $b->av - $a->av;
}

function playerMaReverseSort($a, $b) {
  return $a->ma == $b->ma ? playerSPPsSort($a, $b) : $a->ma - $b->ma;
}

function playerStReverseSort($a, $b) {
  return $a->st == $b->st ? playerSPPsSort($a, $b) : $a->st - $b->st;
}

function playerAgReverseSort($a, $b) {
  return $a->ag == $b->ag ? playerSPPsSort($a, $b) : $a->ag - $b->ag;
}

function playerAvReverseSort($a, $b) {
  return $a->av == $b->av ? playerSPPsSort($a, $b) : $a->av - $b->av;
}

/* Class file for a team */
class Players {
  var $players;

  function Players(&$season) {
    $this->players = array();
    $rs = executeQuery("select p.fk_team_id, player_id, roster_num, name, position, ma, st, ag, av, skills, injured, niggles, completions, touchdowns, interceptions, casualties, mvps, exps, cost from players p, seasons_teams st where st.fk_season_id=$season->id and p.fk_team_id=st.fk_team_id");
    while($row = mysql_fetch_row($rs)) {
      $player = new Player();
      $player->init($row);
      array_push($this->players, $player);
    }
  }
}
?>